import 'package:device_preview/device_preview.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:mall/constant/app_dimens.dart';
import 'package:mall/constant/app_strings.dart';
import 'package:mall/utils/hud/hud_util.dart';

import 'router/route_names.dart';
import 'router/route_pages.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // var _userViewModel = UserViewModel();
  // var _cartViewModel = CartViewModel();
  // await _userViewModel.refreshData();
  // SharedPreferencesUtil.getInstance().getString(AppStrings.TOKEN).then((value) {
  //   if (value != null) {
  //     _cartViewModel.queryCart();
  //   }
  // });

  runApp(DevicePreview(
//      enabled: !kReleaseMode,
    enabled: false,
    builder: (context) => MallApp(),
  ));
}

class MallApp extends StatelessWidget {
  MallApp() {
    // final router = FluroRouter();
    // Routers.configureRoutes(router);
    // Application.router = router;
  }

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: const Size(AppDimens.MAX_WIDTH, AppDimens.MAX_HEIGHT),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (context, child) {
          return GetMaterialApp(
            locale: DevicePreview.locale(context),
            // <--- /!\ Add the locale
            // builder: DevicePreview.appBuilder,
            builder: HUDUtil.init(),
            // <--- /!\ Add the builder
            title: AppStrings.APP_NAME,
            initialRoute: MobileRouteNames.splash,
            getPages: routePages,
            // navigatorKey: Application.navigatorKey,
            debugShowCheckedModeBanner: false,
            // onGenerateRoute: Application.router.generator,
            theme: ThemeData(
              primarySwatch: AppColors.themeColor,
              visualDensity: VisualDensity.adaptivePlatformDensity,
              scaffoldBackgroundColor: AppColors.C_F7F8FC,
              appBarTheme: AppBarTheme(
                backgroundColor: AppColors.C_FFFFFF,
              ),
              // splashColor: Colors.transparent, // 设置 InkWell 的点击效果颜色
            ),
          );
        });
  }
}
